class ValueJudge:
    def __init__(self):
        self.record_time = 0.0
        self.keep_cnt = 0
        self.keep_time = 0.0
    def update(self, current_time, current_value, judge_value, judge_way):
        result = False
        if judge_way == "<":
            result = current_value < judge_value
        elif judge_way == ">":
            result = current_value > judge_value
        elif judge_way == "<=":
            result = current_value <= judge_value
        elif judge_way == ">=":
            result = current_value >= judge_value
        elif judge_way == "==":
            result = current_value == judge_value
        elif judge_way == "!=":
            result = current_value != judge_value
        
        if self.record_time == 0.0:
            self.record_time = current_time
    
        if result:
            self.keep_time = current_time - self.record_time
            self.keep_cnt += 1
        else:
            self.record_time = current_time
            self.keep_time = 0
            self.keep_cnt = 0 

    def timeout(self, current_time, current_value, judge_value, keep_time, judge_way):
        self.update(current_time, current_value, judge_value, judge_way)
        return (keep_time <= self.keep_time)
    def cntout(self, current_time, current_value, judge_value, keep_cnt, judge_way):
        self.update(current_time, current_value, judge_value, judge_way)
        return (keep_cnt <= self.keep_cnt)
